package com.itbaizhan.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itbaizhan.domain.Order;
import com.itbaizhan.dto.OrderDto;
import com.itbaizhan.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author spf
 * @date 2024/5/6
 * @time 17:29
 */
@Controller
@RequestMapping("/shopping")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/order")
    public ModelAndView selectOrder(OrderDto orderDto) {
        // 获取认证对象，从里面拿到对象
        OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) SecurityContextHolder.getContext().getAuthentication().getDetails();
        String tokenValue = details.getTokenValue();

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("order");
        Page<Order> orders = orderService.findOrder(orderDto);
        modelAndView.addObject("token", tokenValue);
        modelAndView.addObject("orders", orders);
        return modelAndView;
    }

}
